<template>
    <div class="waiting-queue-box">
        <commpVxeTable
        :isCanWrap="true"
        :key="commpVxeTableKey"
        :config="dataTableConfig" 
        :columns="columnsVxe" 
        :formItem="formItem"
        ref="acceptanceRegistrationRef"
        >
            <template v-slot:externalOperations="{data}">
                <vxe-form-item>
                    <template>
                        <a-button class="blue-btn" type="primary" icon="plus-square" @click="addInspectionTaskClick({},false)">汇总审评计划</a-button>
                    </template>
                </vxe-form-item>
            </template>
            <template v-slot:fbmksrq_fbmjsrq="{row}" data-desc="审评日期">
                {{ row.fbmksrq }}至{{ row.fbmjsrq }}
            </template>
            <template v-slot:fbmzt_name="{row}">
                <span v-if="row.fbmzt == '已发布'" style="color: #66c24f;border: 1px solid #66c24f;border-radius: 20px;padding:0 5px;">已发布</span>
                <span v-if="row.fbmzt == '已结束'" style="color: #ed5565;border: 1px solid #ed5565;border-radius: 20px;padding:0 5px;">已结束</span>
                <span v-if="row.fbmzt == '未发布'" style="color: #faad14;border: 1px solid #faad14;border-radius: 20px;padding: 0 5px;">未发布</span>
                <span v-if="row.fbmzt == '已作废'" style="color: #a5a1a1;border: 1px solid #a5a1a1;border-radius: 20px;padding: 0 5px;">已作废</span>
            </template>
            <template v-slot:operation_btn="{row}">
                <a-form layout="inline" class="search-form" >
                    <a-form-item v-if="row.fbmzt !== '已发布' && row.fbmzt !== '已作废'" >
                        <a-button class="blue-btn" type="primary" @click="releaseClick(row)">{{row.fbmzt == '已结束'?'重新发起':'发布计划'}}</a-button>
                    </a-form-item>
                    <a-form-item v-if="row.fbmzt == '已发布' && row.fbmzt !== '已作废'" >
                        <a-button class="red-btn" type="primary" @click="endPlanClick(row)">结束计划</a-button>
                    </a-form-item>
                    <a-form-item v-if="row.fbmzt !== '已作废'">
                        <a-button class="orange-btn" type="primary" @click="voidClick(row)">作废计划</a-button>
                    </a-form-item>
                    <a-form-item >
                        <a-button class="green-btn" type="primary" @click="addInspectionTaskClick(row,true)">计划详情</a-button>
                    </a-form-item>
                    <!-- <a-form-item >
                        <a-button v-if="row.fbmzt == '报名中'" class="red-btn" type="primary" @click="deletePlanClick(row)">删除计划</a-button>
                    </a-form-item> -->
                </a-form>
            </template>
        </commpVxeTable>
        <initiateRegistrationComp ref="initiateRegistrationCompRef" @initiateRegistrationSuccess="initiateRegistrationSuccess"/>
        <planDetails ref="planDetailsRef" @initiateRegistrationSuccess="initiateRegistrationSuccess"/>
        <fillFeason ref="fillFeasonRef" @fillFeasonSuccess="fillFeasonSuccess" />
    </div>
</template>
<script>
import assessCheckApi from './service/api'
import commpVxeTable from '@/components/commp-vxe-table/commp-vxe-table.vue'
import blobType from '@/common/blobType'
import moment from 'moment'
import { ybmjhverifySfyjbm, ybmjhbmjbxxByJsbm, ybmjhdeleteBmjbxx, ybmjhzfbmjhjbxx, ybmjhfbbmjhjbxx, } from './service/index'
import initiateRegistrationComp from './initiateRegistrationComp.vue'
import planDetails from './planDetails.vue'
import fillFeason from '../allHandlingPage/manufacturing/planProduction/fillFeason.vue'
export default {
    components:{
        commpVxeTable,
        initiateRegistrationComp,
        planDetails,
        fillFeason,
    },
    props:{
        isRegistrationBtn:{
            type: String,
            required: false
        }
    },
    data(){
        return{
            formItem:[{
                label: '报名状态',
                model: 'fbmzt',
                type:'Select',
                options:[{
                    label: '未发布',
                    value: '未发布'
                },{
                    label: '已发布',
                    value: '已发布'
                },{
                    label: '已结束',
                    value: '已结束'
                },{
                    label: '已作废',
                    value: '已作废'
                }]
            }],
            columnsVxe:[
            { 
                type: 'checkbox', 
                width: 60 ,
                fixed: 'left'
            },{
                title: '计划名称', //列头显示文字
                field: 'fjhmc',
            },{
                title: '报名开始日期', //列头显示文字
                width:195,
                field: 'fbmksrq',
                slots: {
                    // 使用插槽模板渲染
                    default: 'fbmksrq_fbmjsrq',
                },
            },{
                title: '审评类型', //列头显示文字
                field: 'fjcylx',
            },{
                title: '计划状态', //列头显示文字
                field: 'fbmzt',
                width:95,
                slots: {
                    // 使用插槽模板渲染
                    default: 'fbmzt_name',
                },
            },{
                title: '操作',
                field: 'id',
                titleInterval:true,
                slots: {
                    // 使用插槽模板渲染
                    header:'operation_header',
                    default: 'operation_btn',
                },
                fixed: 'right',
                width:278
            }],
            dataTableConfig:{
                api: assessCheckApi.ybmjhqueryBmjbxxPageList,
                rowId: 'id',
                paramet:{
                }
            },
            addEditParameter:{},
            commpVxeTableKey:null,
        }
    },
    watch:{

    },
    mounted(){
        
    },
    methods:{
        addInspectionTaskClick(row,val){
            this.$refs.initiateRegistrationCompRef.getData(row,val)
            this.$refs.initiateRegistrationCompRef.visible = true
        },
        initiateRegistrationSuccess(){
            this.commpVxeTableKey = Date.now()
        },
        planDetailsClick(row){
            this.$refs.planDetailsRef.getData(row)
            this.$refs.planDetailsRef.visible = true
        },
        endPlanClick(row){
            var that = this
            this.$confirm({
                title:'您确认要结束吗？',
                // icon: createVNode(ExclamationCircleOutlined),
                onOk() {
                    ybmjhbmjbxxByJsbm({id:row.id}).then(res=>{
                        if(res.code == 200){
                            that.$message.success(res.message)
                            that.initiateRegistrationSuccess()
                        }else{
                            that.$message.warning(res.message)
                        }
                    })
                }
            })
        },
        deletePlanClick(row){
            var that = this
            this.$confirm({
                title:'您确认要删除吗？',
                // icon: createVNode(ExclamationCircleOutlined),
                onOk() {
                    ybmjhdeleteBmjbxx({id:row.id}).then(res=>{
                        if(res.code == 200){
                            that.$message.success(res.message)
                            that.initiateRegistrationSuccess()
                        }else{
                            that.$message.warning(res.message)
                        }
                    })
                }
            })
        },
        releaseClick(row){//发布
            var that = this
            this.$confirm({
                title:'您确认要发布吗？',
                // icon: createVNode(ExclamationCircleOutlined),
                onOk() {
                    ybmjhfbbmjhjbxx({id:row.id}).then(res=>{
                        if(res.code == 200){
                            that.$message.success(res.message)
                            that.initiateRegistrationSuccess()
                        }else{
                            that.$message.warning(res.message)
                        }
                    })
                }
            })
        },
        voidClick(row){//作废
            this.$refs.fillFeasonRef.getData({
                type:'作废计划',
                modalTitle:'作废原因',
                messageText:'作废原因',
                dataRow:row,
            })
            this.$refs.fillFeasonRef.visible = true
        },
        fillFeasonSuccess(row){
            ybmjhzfbmjhjbxx({id:row.dataRow.id,fbz:row.opinion}).then(res=>{
                if(res.code == 200){
                    this.$refs.fillFeasonRef.visible = false
                    this.$message.success(res.message)
                    this.initiateRegistrationSuccess()
                }else{
                    this.$message.warning(res.message)
                }
            })
        }
    }
}
</script>
<style lang="less">
.waiting-queue-box{
    background: #fff;
    .waiting-content-v{
        height: calc(100vh - 191px -48px);
    }
}
</style>